<template>
	<view class="page b-bg haveBar" id="scrollWrap" >
		<view class="userBox">
			<view class="logoBox" @tap='goIndex'>
				<image src="../../static/img/logo.png" mode="" class="logo"></image>
			</view>
			<user :num="num"></user>
		</view>
	    <banner :banner_image="banner_image"></banner>
		<view class="blockTab">
		   <tab current="1" scrollLeft='0' :goId="goId"></tab>
		</view>
		<view class="for-infoBox">
			<div class="p" v-if="dec.description" v-html="dec.description"></div>
		</view>
		<barCon :is_up="is_up"></barCon>
	</view>
</template>

<script>
	import mixin from '@/util/mixin.js';
	import baseUrl from "@/util/path.js"
	export default {
		mixins:[mixin],
		data() {
			return {
				id:"",
				dec:{},
				goId:"",
				moblie:"",
				code:"",
				title:'',
				is_up:false,
				num:'',
				banner_image:''
			}
		},
		
		onLoad(option) {
			// console.log(option);
			this.moblie = option.mobile;
			// debugger;
			this.code = option.code;
			this.goId = option.id;
			this.title = option.name;
			// console.log(this.title);
			// alert(this.moblie);
			// alert(this.code);
			if(this.moblie) {
				// alert('运行登录');
				this.login();
			} else {
				this.getdec();
			}
		},
		methods: {
			async login () {
				const _this = this;
				const code = decodeURIComponent('3_' + this.code);
				let result = code.replace(/\s+/g, "+");
				// console.log(this.code);				
				uni.request({
					url: baseUrl.lb + 'oauth/token',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: 'post',
					data:{
						grant_type:'sms',
						client_id:baseUrl.client_id,
						client_secret:baseUrl.client_secret,
						scope:"",
						username: this.moblie,
						verify_code:result
					},
					success: (res) => {
						if(res.data.access_token) {
							uni.setStorageSync('token',res.data.access_token);
							uni.setStorageSync('refresh',res.data.refresh_token);
							_this.getUserInfo();
							setTimeout(() => {
								_this.getUserInfo()
							},10)
						} else {
							_this.toast(res.data.message);
						}
					},
					fail: (err) => {
						
					}
				})
			},
			async getUserInfo() {
				const res = await this.$http({
					  url:'api/user/get_user_info',
					  method:'post',
					  data:{}
				 },"lb")
				 //console.log(res);
				 //console.log(res);
				 if(res) {
					 
					 this.num = res.user_mobile;
					 uni.setStorageSync('user',res);
					 this.toast("登录成功");
					 this.getdec();
				 }
			},
			async getdec() {
				// console.log('运行');
				const res = await this.$httpPub({
					  url: 'activity/'+ this.goId,
					  method:'get',
					  data:{}
				})
			   this.dec = res;
			   this.banner_image = this.dec.banner_image;
			   this.is_up = this.dec.is_upload_btn;
			}
	}
}
</script>

<style lang="scss">
	
	#scrollWrap {
		height: auto !important; 
	}
   .page {
   		.add-form {
   			padding: 0;
   		}
   	}
   .block {
   	  width: 100%;
   	  padding: 0rpx 34rpx 40rpx;
   }
   .for-infoBox {
	       // padding-bottom: 0;
		padding: 0 60rpx 120rpx;  
		.p {
			width: 100%;
		}
		 img {
		 	width: 100% !important;
		 }  
		 
	
	   .for-inner {
		   // background-color: #fff;
		   padding: 28rpx;
		   padding-bottom: 7rpx;
		   border-radius: $border-radius;
		   overflow: hidden;
		   box-sizing: border-box;
		   .img-title {
			   width: 281rpx;
			   height: 66rpx;
		   }
		   .for-cont {
			   font-size: 28rpx;
			   line-height: 1.6;
			   .for-cont-inner {
				   overflow: hidden;
			   }
			   .p {
				   margin-bottom: 20rpx;
			   }
		   }
	   }
   }
</style>
